﻿<%@ Page Language="C#" MasterPageFile="~/Pages/Base/ListItemBase.master" CodeFile="~/Pages/Base/ListItemBase.cs" Inherits="ListItemBasePage" %>
<asp:Content ID="content" runat="server" ContentPlaceHolderID="addContent">
    <asp:HyperLink ID="addSYML" Text="新增索引" runat="server" ></asp:HyperLink>
 </asp:Content>
<script runat="server">
    
    // 数据库交互对象
    private StateGrid.ZWQK.ZWQK_DAO dao;

    private IList<StateGrid.ZWQK.ZWQK_SYML> data;
    
    // 当前分类编码
    private String flbm;
    // 中文关键字
    private String zwmc;

    private StateGrid.User.User login;

    protected override void DoInit()
    {
        this.dao = new StateGrid.ZWQK.ZWQK_DAO();
        
        this.flbm = ParseStringQuery("catalog");
        this.zwmc = ParseStringQuery("keyword");

        //判断用户是否登录
        this.login = (StateGrid.User.User)Session["login"];
        if (null == this.login || this.login.role == StateGrid.User.UserRole.NORMAL)
        {
            this.addSYML.Visible = false;
        }
        else
        {
            //分类编码为空则不显示新增篇名链接
            if (null == this.flbm || this.flbm.Length != 6)
            {
                this.addSYML.Visible = false;
            }
            else
            {
                this.addSYML.NavigateUrl = StateGrid.GlobalVariables.GlobalZWQK.ADDSYML_PAGE + "?flbm=" + this.flbm;
            }
        }
    }

    protected override void SetItemFields()
    {
        RegisterKeyField("sybm");
        
        AddBoudField("索引编码", "sybm", 0,15);
        AddBoudField("中文名称", "zwmc", 12,30);
        AddBoudField("主办单位", "zbdw", 20,40);
        
        AddHyperLinkField("篇名",
                          StateGrid.GlobalVariables.GlobalZWQK.LISTPM_PAGE + "?sybm={0}",
                          new string[] {"sybm"}); 
        
        AddHyperLinkField("编辑",
                          StateGrid.GlobalVariables.GlobalZWQK.EDITSYML_PAGE + "?sybm={0}",
                          new string[] {"sybm"});
    }

    protected override int GetItemCount()
    {
        return dao.countQueryZwqkSYML(flbm, zwmc);
    }

    protected override object GetItemSource(int begin, int end)
    {
        data = dao.queryZwqkSYML(flbm, zwmc, begin, end);
        return data;
    }

    protected override bool OnDelete(DataKey dataKey, out string message)
    {
        int ret = dao.deleteZwqkSYMLBySybm(dataKey.Value as string);
        if (ret >= 1)
        {
            message = "删除成功" ;
            return true;
        }

        message = "删除失败";
        return false;
    }

    protected override Boolean HasDeleteField()
    {
        Boolean show = false;
        StateGrid.User.User user = (StateGrid.User.User)Session["login"];

        //未登录跳转到登录页
        if (null == user)
        {
            StateGrid.GlobalMethod.RedirectLogin(Response);
            return show;
        }

        //不是普通用户（即为管理员或编辑员），登录则显示删除用户
        if (user.role != StateGrid.User.UserRole.NORMAL)
        {
            show = true;
        }
        
        return show;
    }
</script>
